package com.itheima.redbaby.activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.itheima.redbaby.BaseActivity;
import com.itheima.redbaby.R;
import com.itheima.redbaby.engine.ProductEngine;
import com.itheima.redbaby.factory.DaoAndEngineFactory;
import com.itheima.redbaby.utils.PromptManager;

public class ProductDescActivity extends BaseActivity {
	private TextView tv_desc_name;
	private TextView tv_desc_value;
	private TextView titleBack;
	private int pId;
	private String product_name;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.prod_description_activity);
		
		pId = getIntent().getIntExtra("pId", 0);
		product_name = getIntent().getStringExtra("pName");
		
		init();
		getData();
	}
	
	private void init() {
		titleBack = (TextView) findViewById(R.id.titleBack);
		tv_desc_name = (TextView) findViewById(R.id.tv_desc_name);
		tv_desc_value = (TextView) findViewById(R.id.tv_desc_value);
		
		titleBack.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	private void getData() {
		new MyHttpTask() {
			@Override
			protected void onPreExecute() {
				PromptManager.showProgressDialog(ProductDescActivity.this);
			};
			@Override
			protected Object doInBackground(Void... params) {
				ProductEngine productEngine = DaoAndEngineFactory.getImpl(ProductEngine.class);
				String desc = productEngine.getProductDesc(pId);
				return desc;
			}
			@Override
			protected void onPostExecute(Object result) {
				PromptManager.closeProgressDialog();
				String product_desc_val = (String) result;
				tv_desc_name.setText(product_name);
				tv_desc_value.setText(product_desc_val);
			}
		}.executeHttp();
	}
}
